<template>
    <!-- 常规登录 -->
    <div class="common-login">
        <el-form-item label="用户名" prop="userName">
            <el-input type="text" v-model="loginForm.userName" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密  码" prop="password">
            <el-input type="password" v-model="loginForm.password" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item class="captcha" label="验证码" prop="captcha">
            <el-input maxlength="5" type="text" v-model="loginForm.captcha" ref="captcha"
                @keydown.native.enter="submitForm('loginForm')"></el-input>
            <span>123</span>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="submitForm('loginForm')">提交</el-button>
            <el-button @click="resetForm('loginForm')">重置</el-button>
        </el-form-item>
        <!-- 手机登录图标 -->
        <el-form-item>
            <div class="sms" @click="smsLogin()">
                <svg class="icon icon-shouji" aria-hidden="true">
                    <use xlink:href="#icon-shoujichongzhi"></use>
                </svg>
                <a href="javascript:;" style="font-size: 16px">切换短信登入</a>
            </div>
        </el-form-item>
    </div>
</template>
<script>
// 表单验证思路：当前组件的loginForm变化同步到父组件的loginForm即可
export default {
    props: ['sms'],
    data() {
        return {
            isSmsLogin: true, // 控制是否切换短信登录
            loginForm: {
                username: "",
                password: "",
                captcha: ""
            }
        }
    },
    methods: {
        submitForm(formName) {
            console.log(formName);
            this.$emit("submit")
        },
        resetForm(formName){
            this.$emit("reset")
        },

        smsLogin(){
            this.sms=false
        }
    },

    watch:{
        // 监听loginForm的变化
        loginForm:{
            handler(newVal){
                // console.log(newVal);
                this.$emit('syncLoginForm',newVal)
            },
            deep:true
        }
    },
}
</script>

<style lang="less" scoped>
.common-login {


    /deep/.el-form-item__label {
        color: rgb(242, 102, 26);
        font: 20px/40px "楷体";
    }

    .captcha {
        .el-input {
            width: 130px;
            float: left;
            border-radius: 5px 0px 0 5px;
        }

        span {
            width: 120px;
            font: 20px/40px "";
            float: right;
            border-radius: 0 5px 5px 0px;
            background: #fff;
        }
    }

    .sms {
        display: flex;
        justify-content: center;
        align-items: center;
        color: rgb(242, 102, 26);
        cursor: pointer;

        svg {
            width: 25px;
            height: 30px;
            margin-right: 5px;
        }

        a {
            text-decoration: none;
            color: rgb(242, 102, 26);
        }
    }
}
</style>
